package org.sqlproc.sample.tutorial.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Type;
import org.hibernate.validator.constraints.NotEmpty;

/**
*
* Entity representing Movie.
*/
@Entity
@Table(name = "MOVIE")
@PrimaryKeyJoinColumn(name = "MEDIA")
@ForeignKey(name = "FK_MOVIE_MEDIA")
//@EntityListeners({org.hibernate.validator.event.JPAValidateListener.class
//})
public class Movie extends Media {
    @Column(name = "URLIMDB", nullable = false, length = 100, unique = true)
    @NotEmpty
    private String urlIMDB;
    @Column(name = "PLAYLENGTH", nullable = false)
    @NotEmpty
    private Integer playLength;
    @Column(name = "CATEGORY")
    @Type(type = "Genre")
    private Genre category;

    public Movie() {
    }

    public Movie(String title, String urlIMDB) {
        super(title);
//        Validate.notNull(urlIMDB);
        this.urlIMDB = urlIMDB;
    }

    public String getUrlIMDB() {
        return urlIMDB;
    }

    public Integer getPlayLength() {
        return playLength;
    }

    public void setPlayLength(Integer playLength) {
        this.playLength = playLength;
    }

    public Genre getCategory() {
        return category;
    }

    public void setCategory(Genre category) {
        this.category = category;
    }

    /**
     * This method is used by toString. It specifies what to
     * include in the toString result.
     * @return true if the field is to be included in toString
     */
//    protected boolean acceptToString(Field field) {
//        if (super.acceptToString(field)) {
//            return true;
//        } else {
//            if (field.getName().equals("category")) {
//                return true;
//            }
//            return false;
//        }
//    }

    /**
     * This method is used by equals and hashCode.
     * @return {@link #getUrlIMDB}
     */
    public Object getKey() {
        return getUrlIMDB();
    }
}
